//
//  ApiConstant.m
//  bsl-sdk
//
//  Created by Fanty on 13-12-1.
//
//

#import "ApiConstant.h"

#ifndef PRODUCTION_APP
#define PRODUCTION_APP
#endif

@implementation ApiConstant

+(ApiConstant*)defaultConstant{
    static ApiConstant *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[ApiConstant alloc] init];
    });
    return sharedInstance;
}

-(id)init{
    self=[super init];
#ifdef DEBUG
    self.sandBoxEnviroment=YES;
#else
    self.sandBoxEnviroment=NO;
#endif
#ifndef PRODUCTION_APP
    self.appKey=@"3cab23944e145900508fb43b7f862b49";
    self.appSecret=@"e1ac12d9-2ef4-41bb-a097-09826d251c0a";
    self.serverURLHost =@"10.108.1.217:18860";
#else
    self.appKey=@"9ac10bdf29e6cf120294703c95a60878";
    self.appSecret=@"2f1d8975-1dfe-4c4e-af08-28a80c824dad";
    self.serverURLHost =@"115.28.1.119:18860";
#endif
    return self;
}

-(NSURL*)appCheckClient{
    NSString* url=[NSString stringWithFormat:@"http://%@/mam/api/mam/clients/apps/%@/%@/%@/validate",self.serverURLHost,@"ios",[[NSBundle mainBundle] bundleIdentifier],[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ];
    return [NSURL URLWithString:url];
}

-(NSURL*)appVersionCheck{
    NSString* url=[NSString stringWithFormat:@"http://%@/mam/api/mam/clients/update/ios/%@/?ts=%f&appKey=%@",self.serverURLHost,[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"], [NSDate timeIntervalSinceReferenceDate],self.appKey];
    return [NSURL URLWithString:url];

}

-(NSURL*)attachmentByIdURL:(NSString*)aId accountToken:(NSString*)accountToken{
    
    NSString* build=[NSString stringWithFormat:@"http://%@/mam/api/mam/clients/files/%@?appKey=%@",self.serverURLHost,aId,self.appKey];
    if([accountToken length]>0){
        build=[build stringByAppendingFormat:@"&sessionKey=%@",accountToken];
    }
    return [NSURL URLWithString:build];
}

-(NSString*)attachmentByAIdWithNoAppKey:(NSString*)aId{
    NSString* build=[NSString stringWithFormat:@"http://%@/mam/api/mam/clients/files/%@",self.serverURLHost,aId];
    return [NSURL URLWithString:build];

}


-(NSURL*)applicationNewVersionLink:(NSString*)downloadUrl{
    NSString *url = [NSString stringWithFormat:@"itms-services://?action=download-manifest&url=%@", [NSString stringWithFormat:@"%@%@appKey%@%@",downloadUrl,@"%3F",@"%3D",self.appKey]];
    return [NSURL URLWithString:url];
    

}

-(NSURL*)deviceRegisterURL{
    return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/push/api/checkinservice/checkins",self.serverURLHost]];
    
}

@end
